<?php
namespace Tbf\Crypto;
/**
 * 使用openssl加密解密
 * @deprecated
 */
 class OpensslCrypto extends Crypto{
    static $cipherTable = array(
            'aes-256'=>array('cbc'=>'AES-256-CBC')
    );
    static function canLoad(){
        return function_exists('openssl_encrypt');
    }
    function dHash($data,$hashType){
        return openssl_digest( $data,$hashType,true );
    }
    function dCipherEn($data, $cipherType, $mode, $key, $iv){
        $method = self::$cipherTable[$cipherType][$mode];
        return openssl_encrypt($data, $method, $key,true,$iv);
    }
    function dCipherDe($data, $cipherType, $mode, $key, $iv){
        $method = self::$cipherTable[$cipherType][$mode];
        return openssl_decrypt($data, $method, $key,true,$iv);
    }
    static function getCipherList(){
        return openssl_get_cipher_methods();
    }
    function cipherIvSize($cipherType){
        return McryptCrypto::dObj()->cipherIvSize($cipherType);
    }
    function cipherKeySize($cipherType){
        return McryptCrypto::dObj()->cipherKeySize($cipherType);
    }
    function cipherBlockSize($cipherType){
        return McryptCrypto::dObj()->cipherBlockSize($cipherType);
    }
    static function dObj(){
        static $cache = null;
        if ($cache===null){
            $cache = new static;
        }
        return $cache;
    }
}

